/*
 * @Date: 2022-04-06 10:40:58
 * @LastEditors: sailornpg
 * @LastEditTime: 2022-04-23 15:33:26
 * @FilePath: \weibovue\src\store\index.ts
 * @Description: vuex配置
 */
import { UserData } from "../api/types";
import { GlobalProps, atMeReplyItem, atMeBlogItem } from "./types";
import { createStore } from "vuex";
import createPersistedState from "vuex-persistedstate";
import { FanslistType, followListType } from "../components/createWeiBo/types";
const store = createStore<GlobalProps>({
  state: {
    //是否登陆状态
    isLogin: false,
    //用户信息
    userInfos: {},
    //加载中
    isLoading: false,
    //粉丝信息
    fansData: {},
    //关注人信息
    followingData: {},
    //提到我的总数量数量
    atMeCount: 0,
    //回复我的数量
    replyCount: 0,
    //博客@总数量
    atMeblogCount: 0,
    //提到我的评论回复
    atMeReplyList: [],
    //提到我的博客列表
    atMeBlogList: [],
  },
  actions: {},
  mutations: {
    //更新回复我的数量
    updateReplyCount: (state: GlobalProps, count: number) => {
      state.replyCount = count;
    },
    //更新@我的博客数量
    updateAtBlogCount: (state: GlobalProps, count: number) => {
      state.atMeblogCount = count;
    },
    //更新登陆状态
    updateLoginStatus: (state: GlobalProps, flag: boolean) => {
      // console.log("标志是", flag);
      state.isLogin = flag;
    },
    //更新用户信息
    updateUserInfo: (state: GlobalProps, data: UserData) => {
      // console.log("信息是", data);
      state.userInfos = data;
    },
    //设置加载状态
    setIsloadingStatus: (state: GlobalProps, flag: boolean) => {
      state.isLoading = flag;
    },
    //更新粉丝数据
    updateFansData: (state: GlobalProps, data: FanslistType) => {
      state.fansData = data;
    },
    //更新关注数据
    updateFollowingData: (state: GlobalProps, data: followListType) => {
      state.followingData = data;
    },
    //更新@我的数量
    updateAtMeCount: (state: GlobalProps, count: number) => {
      state.atMeCount = count;
    },
    //更新提到我的评论回复
    updateAtMeReplyList: (state: GlobalProps, data: atMeReplyItem[]) => {
      // console.log(data);
      state.atMeReplyList = data;
    },
    //更新提到我的博客列表
    updateAtMeBlogList: (state: GlobalProps, data: atMeBlogItem[]) => {
      state.atMeBlogList = data;
      // console.log("state里面是", state.atMeBlogList);
    },
    //清零评论回复
    resetAtMeReplyList: (state: GlobalProps, data: atMeReplyItem[]) => {
      state.atMeReplyList = [];
    },
  },
  getters: {},
  plugins: [
    //持久化
    createPersistedState({
      storage: window.sessionStorage,
    }),
  ],
});
export default store;
